<?php

namespace  Ekadmin\Controller;

class ConfigController extends CommonController
{
        public  function index()
        {
             $map['uniacid'] = $this->uniacid;
             $data  = M('config')->where($map)->find();
             $this->assign('data',$data);
             $this->display();
        }




        public function  update()
        {
            if(IS_POST){
                $data = I('post.');
                $fh = new \Vendor\FileHelper();

                if($data['apiclient_cert']){

                    $filename ='./ThinkPHP/Library/Vendor/campanyPay/cert/apiclient_cert.pem';
                    $fh::filePutContents($filename,$data['apiclient_cert']);

                }

                if($data['apiclient_key']){

                    $filename ='./ThinkPHP/Library/Vendor/campanyPay/cert/apiclient_key.pem';
                    $fh::filePutContents($filename,$data['apiclient_key']);

                }

                $obj = M('config');
                $con = M('config')->where(['uniacid'=>$this->uniacid])->find();
                if($con){
                    //$data['updatetime'] = time();
                    $obj->where(['uniacid'=>$this->uniacid])->save($data);
                    S('shopconfig',null);
                }else{
                    $data['uniacid'] = $this->uniacid;
                    $data['addtime'] = time();
                    $obj->add($data);
                }


                ajax_return(0,'保存成功',U('index'));
            }
        }
        
        //清除缓存
        public function clearcache(){
            $fh = new \Vendor\FileHelper();
            $filename ='./Runtime';
            $fh::deldir($filename);
            $this->success("清除成功");
        }



}